package com.ruoyi.web.controller.doctor;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.system.domain.vo.SlicesDetailVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TimeSlices;
import com.ruoyi.system.service.ITimeSlicesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 时间片Controller
 * 
 * @author Wu Zhongfu
 * @date 2022-02-07
 */
@RestController
@RequestMapping("/doctor/slices")
public class TimeSlicesController extends BaseController
{
    @Autowired
    private ITimeSlicesService timeSlicesService;

    /**
     * 查询时间片列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TimeSlices timeSlices)
    {
        startPage();
        List<TimeSlices> list = timeSlicesService.selectTimeSlicesList(timeSlices);
        return getDataTable(list);
    }

    @GetMapping("/listByDetails")
    public TableDataInfo listByDetails(SlicesDetailVo timeSlices)
    {
        startPage();
        List<SlicesDetailVo> list = timeSlicesService.listByDetails(timeSlices);
        return getDataTable(list);
    }

    @GetMapping("/listByFreeTimeId/{freeTimeId}")
    public TableDataInfo listByFreeTimeId(@PathVariable("freeTimeId") Integer freeTimeId)
    {
        startPage();
        List<SlicesDetailVo> list = timeSlicesService.listByFreeTimeId(freeTimeId);
        return getDataTable(list);
    }

    @DataScope(deptAlias = "d",userAlias = "u")
    @GetMapping("/listByDetailsByUserId")
    public TableDataInfo listByDetailsByUserId(SlicesDetailVo timeSlices)
    {
        startPage();
        timeSlices.setUserId(getLoginUser().getUserId());
        List<SlicesDetailVo> list = timeSlicesService.listByDetails(timeSlices);
        return getDataTable(list);
    }

    /**
     * 导出时间片列表
     */
    @Log(title = "时间片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TimeSlices timeSlices)
    {
        List<TimeSlices> list = timeSlicesService.selectTimeSlicesList(timeSlices);
        ExcelUtil<TimeSlices> util = new ExcelUtil<TimeSlices>(TimeSlices.class);
        util.exportExcel(response, list, "时间片数据");
    }

    /**
     * 获取时间片详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(timeSlicesService.selectTimeSlicesById(id));
    }

    /**
     * 新增时间片
     */
    @PreAuthorize("@ss.hasPermi('doctor:slices:add')")
    @Log(title = "时间片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TimeSlices timeSlices)
    {
        return toAjax(timeSlicesService.insertTimeSlices(timeSlices));
    }

    /**
     * 修改时间片
     */
    @PreAuthorize("@ss.hasPermi('doctor:slices:edit')")
    @Log(title = "时间片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TimeSlices timeSlices)
    {
        return toAjax(timeSlicesService.updateTimeSlices(timeSlices));
    }

    /**
     * 删除时间片
     */
    @PreAuthorize("@ss.hasPermi('doctor:slices:remove')")
    @Log(title = "时间片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(timeSlicesService.deleteTimeSlicesByIds(ids));
    }
}
